package prefix.payment;

import java.util.List;

import prefix.transaction.BasicTransaction;
import prefix.util.JPAUtil;
import prefix.util.OverallUtil;
import prefix.util.jpaQueryfier.JpaQueryfier;
import models.Transaction;

public class PaymentExeProcessor {

    @SuppressWarnings("unchecked")
    public static void executePaymentTrans() {
        String sql = " select * from transaction where status = 0 and type in ("
                + OverallUtil.INSQL(Transaction.Type.T5_BORROWER_PAY_MANAGEMENT_FEE,
                        Transaction.Type.T6_LENDER_PAY_SERVICE_FEE, Transaction.Type.T8_BORROWER_MTHLY_PAY_TO_LENDER)
                + ") order by id asc ";

        List<Transaction> transList = (List<Transaction>) new JpaQueryfier(sql, JPAUtil.em()).queryfyNative(
                Transaction.class).getResultList();

        if (transList == null || transList.size() <= 0)
            return;
        System.out.println(" payment transaction size: " + transList.size());
        for (Transaction trans : transList) {
            try {
                BasicTransaction.executeNow(trans);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }
}
